"""
Software engineering (required):

You are given a directed graph.  Find all nodes where the in-degree is N.  You will need to define the data structure
and write implementation code.

"""
graph = {
        "A": set("BCD"),
        "B": set("ADE"),
        "C": set("FGI"),
        "D": set("EHI")
        }


def in_degree(G, N):
    """
    :param G:  directedGraph
    :param N:  int target in_degree N
    :return:   list [nodes]
    """
    in_degree_map = {}
    for edge in G:
        for node in G[edge]:
            if node not in in_degree_map:
                in_degree_map[node] = 1
            else:
                in_degree_map[node] += 1
    res = []
    for n in in_degree_map:
        if in_degree_map[n] == N:
            res.append(n)
    print(res if res else "in_degree is N not exist!")
    return res

in_degree(graph, 2)